from sqlalchemy import Column, Integer, String, Text, DateTime, JSON, BigInteger, ForeignKey,Index
from sqlalchemy.sql import func
from db.database import Base
from utils.snowflake import snowflake

class MedicalCaseModel(Base):
  __tablename__ = "medical_case"
  __table_args__ = (
    Index('idx_shop_patient', 'shop_id', 'patient_id'),  # 复合索引
    Index('idx_shop_patient_status', 'shop_id', 'patient_id', 'status'),  # 包含状态的复合索引
    {
      "comment": "医疗病例记录表，存储患者的病例信息、诊断结果和治疗方案等"
    }
  )
  
  # 也可以在下列字段添加 index=True, 表示添加单一索引
  
  # 使用雪花算法生成ID
  id = Column(BigInteger, primary_key=True, default=snowflake.next_id)
  # 关系映射ForeignKey("user.id"), 外键关联user表的id字段
  # patient_id = Column(String(36),ForeignKey("user.id"), nullable=False,comment="患者ID")
  patient_id = Column(String(36),  nullable=False,comment="患者ID")
  shop_id = Column(String(36),  nullable=False,comment="店铺ID")
  patient_name = Column(String(50), nullable=True,comment="患者姓名")
  description = Column(Text, nullable=False, comment="病例描述")
  case_images = Column(String(500), nullable=False, comment="病例图片路径")
  diagnosis = Column(String(255), nullable=True, comment="诊断结果")
  treatment_plan = Column(Text, nullable=True, comment="治疗方案")
  create_time = Column(DateTime(timezone=True), server_default=func.now(), comment="创建时间")
  update_time = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), comment="更新时间")
  doctor_id = Column(String(36),  nullable=True, comment="医生ID")
  doctor_name = Column(String(50), nullable=True, comment="医生姓名")
  deleted_at = Column(DateTime(timezone=True), nullable=True, default=None, comment="删除时间")
  status = Column(Integer, default=1,comment="状态")
